/**
 * <copyright>
 * </copyright>
 *

 */
package br.pucrio.inf.tamdera.impl;

import br.pucrio.inf.tamdera.ConceptDeclaration;
import br.pucrio.inf.tamdera.ConceptMap;
import br.pucrio.inf.tamdera.Constraint;
import br.pucrio.inf.tamdera.ConstraintSetDeclaration;
import br.pucrio.inf.tamdera.TamderaPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Concept Declaration</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link br.pucrio.inf.tamdera.impl.ConceptDeclarationImpl#getName <em>Name</em>}</li>
 *   <li>{@link br.pucrio.inf.tamdera.impl.ConceptDeclarationImpl#getConceptMapper <em>Concept Mapper</em>}</li>
 *   <li>{@link br.pucrio.inf.tamdera.impl.ConceptDeclarationImpl#getConstraints <em>Constraints</em>}</li>
 *   <li>{@link br.pucrio.inf.tamdera.impl.ConceptDeclarationImpl#getReferredConstraintSets <em>Referred Constraint Sets</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ConceptDeclarationImpl extends ParagraphImpl implements ConceptDeclaration
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getConceptMapper() <em>Concept Mapper</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConceptMapper()
   * @generated
   * @ordered
   */
  protected ConceptMap conceptMapper;

  /**
   * The cached value of the '{@link #getConstraints() <em>Constraints</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConstraints()
   * @generated
   * @ordered
   */
  protected EList<Constraint> constraints;

  /**
   * The cached value of the '{@link #getReferredConstraintSets() <em>Referred Constraint Sets</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getReferredConstraintSets()
   * @generated
   * @ordered
   */
  protected EList<ConstraintSetDeclaration> referredConstraintSets;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ConceptDeclarationImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return TamderaPackage.Literals.CONCEPT_DECLARATION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TamderaPackage.CONCEPT_DECLARATION__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ConceptMap getConceptMapper()
  {
    return conceptMapper;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetConceptMapper(ConceptMap newConceptMapper, NotificationChain msgs)
  {
    ConceptMap oldConceptMapper = conceptMapper;
    conceptMapper = newConceptMapper;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER, oldConceptMapper, newConceptMapper);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setConceptMapper(ConceptMap newConceptMapper)
  {
    if (newConceptMapper != conceptMapper)
    {
      NotificationChain msgs = null;
      if (conceptMapper != null)
        msgs = ((InternalEObject)conceptMapper).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER, null, msgs);
      if (newConceptMapper != null)
        msgs = ((InternalEObject)newConceptMapper).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER, null, msgs);
      msgs = basicSetConceptMapper(newConceptMapper, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER, newConceptMapper, newConceptMapper));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Constraint> getConstraints()
  {
    if (constraints == null)
    {
      constraints = new EObjectContainmentEList<Constraint>(Constraint.class, this, TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS);
    }
    return constraints;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ConstraintSetDeclaration> getReferredConstraintSets()
  {
    if (referredConstraintSets == null)
    {
      referredConstraintSets = new EObjectResolvingEList<ConstraintSetDeclaration>(ConstraintSetDeclaration.class, this, TamderaPackage.CONCEPT_DECLARATION__REFERRED_CONSTRAINT_SETS);
    }
    return referredConstraintSets;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER:
        return basicSetConceptMapper(null, msgs);
      case TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS:
        return ((InternalEList<?>)getConstraints()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case TamderaPackage.CONCEPT_DECLARATION__NAME:
        return getName();
      case TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER:
        return getConceptMapper();
      case TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS:
        return getConstraints();
      case TamderaPackage.CONCEPT_DECLARATION__REFERRED_CONSTRAINT_SETS:
        return getReferredConstraintSets();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case TamderaPackage.CONCEPT_DECLARATION__NAME:
        setName((String)newValue);
        return;
      case TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER:
        setConceptMapper((ConceptMap)newValue);
        return;
      case TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS:
        getConstraints().clear();
        getConstraints().addAll((Collection<? extends Constraint>)newValue);
        return;
      case TamderaPackage.CONCEPT_DECLARATION__REFERRED_CONSTRAINT_SETS:
        getReferredConstraintSets().clear();
        getReferredConstraintSets().addAll((Collection<? extends ConstraintSetDeclaration>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case TamderaPackage.CONCEPT_DECLARATION__NAME:
        setName(NAME_EDEFAULT);
        return;
      case TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER:
        setConceptMapper((ConceptMap)null);
        return;
      case TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS:
        getConstraints().clear();
        return;
      case TamderaPackage.CONCEPT_DECLARATION__REFERRED_CONSTRAINT_SETS:
        getReferredConstraintSets().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case TamderaPackage.CONCEPT_DECLARATION__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case TamderaPackage.CONCEPT_DECLARATION__CONCEPT_MAPPER:
        return conceptMapper != null;
      case TamderaPackage.CONCEPT_DECLARATION__CONSTRAINTS:
        return constraints != null && !constraints.isEmpty();
      case TamderaPackage.CONCEPT_DECLARATION__REFERRED_CONSTRAINT_SETS:
        return referredConstraintSets != null && !referredConstraintSets.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //ConceptDeclarationImpl
